package com.springMVC.service.impl;

import com.springMVC.dao.OrderDao;
import com.springMVC.util.MapUnderscoreToCamelCase;
import com.springMVC.service.OrderService;
import com.springMVC.util.Rest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能模块说明
 * Created with IntelliJ IDEA.
 * User: AnCong
 * Date: 2017/4/27
 */
@Service
public class OrderServiceImpl implements OrderService{
    @Autowired
    private OrderDao orderDao;

    @Override
    public Rest orderList(Map params){
        Rest rest=new Rest();
        try{
            if(params.get("rows")!=null&&params.get("page")!=null&&!params.get("rows").equals("")&&!params.get("page").equals("")){
                Integer rows = Integer.parseInt(params.get("rows").toString());
                Integer offset = (Integer.parseInt(params.get("page").toString()) - 1) * rows;
                params.put("rows", rows);
                params.put("offset", offset);
            }else{
                params.put("rows", 20);
                params.put("offset", 0);
            }
            List<Map> orderList=orderDao.orderList(params);
            List<Map> orderListSum=orderDao.orderListSum(params);
            Map resultMap=new HashMap();
            resultMap.put("rows",orderList);
            resultMap.put("total",orderListSum.get(0).get("total"));
            rest.setIsSuccess(true);
            rest.setData(resultMap);
            rest.setMessage("查询订单列表成功！");
        }catch(Exception se){
            rest.setIsSuccess(false);
            rest.setError("Impl-orderList查询列表错误");
            se.printStackTrace();
        }
        return rest;
    }
}
